package com.firstclass.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.firstclass.dao.TakescoreDao;
import com.firstclass.entity.TakescoreEntity;
import com.firstclass.service.TakescoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("takescoreService")
public class TakescoreServiceImpl extends ServiceImpl<TakescoreDao, TakescoreEntity> implements TakescoreService {

    @Autowired
    private TakescoreDao takescoreDao;

    @Override
    public List<TakescoreEntity> queryByCondition(String name, String num, String course) {
        final QueryWrapper<TakescoreEntity> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(name)) {
            wrapper.like("name", name);
        }
        if (StrUtil.isNotBlank(num)) {
            wrapper.like("num", num);
        }
        if (StrUtil.isNotBlank(course)) {
            wrapper.like("course", course);
        }
        return this.list(wrapper);
    }

    @Override
    public boolean save(TakescoreEntity takescoreEntity) {
        if (takescoreEntity.getId() == null) {
            takescoreDao.insert(takescoreEntity);
        } else {
            takescoreDao.updateById(takescoreEntity);
        }
        return true;
    }

}